package org.stream.answerduel.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.stream.answerduel.dto.Result;
import org.stream.answerduel.service.FriendService;
import org.stream.answerduel.vo.UserVo;

import java.util.List;

/**
 * 功能描述：用于处理对好友操作的控制器
 * @author  郭榕
 * @date   2019/7/122 18:50
 *
 */
@Api("好友控制器接口")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;

    /**
     * @date 2019/7/22 18:46
     * 功能描述：删除好友
     */
    @ApiOperation(value = "删除", notes = "删除好友，单方删除则双方同时删除")
    @ApiImplicitParams({})
    @GetMapping("/deleteFriend")
    public Result deleteFriend( Long userId , Long friendId )
    {
        friendService.deleteFriend(userId , friendId);
        return new Result().ok("删除成功");
    }

    /**
     * @date 2019/7/22 18:50
     * 功能描述：通过申请
     */
    @ApiOperation(value = "通过申请", notes = "通过好友申请，双方互相添加好友")
    @ApiImplicitParams({})
    @GetMapping("/passAdd")
    public Result passAdd( Long userId , Long friendId )
    {
        friendService.saveFriend(userId , friendId);
        return new Result().ok("申请通过");
    }

    /**
     * @date 2019/7/22 18:50
     * 功能描述：发起申请
     */
    @ApiOperation(value = "申请添加好友", notes = "单方面申请")
    @ApiImplicitParams({})
    @GetMapping("/addApply")
    public Result addApply(Long userId , Long friendId )
    {
        friendService.applyFriend(userId , friendId);
        return new Result().ok("成功发起申请");
    }

    /**
     * @date 2019/7/22 18:50
     * 功能描述：查看申请
     */
    @ApiOperation(value = "查看申请", notes = "查看有谁申请我")
    @ApiImplicitParams({})
    @GetMapping("/checkApply")
    public Result<List<UserVo>> checkApply(Long userId)
    {
        List<UserVo> userVoList = friendService.checkApply(userId);
        return new Result<List<UserVo>>().ok("查询结果如下", userVoList);
    }

    /**
     * @date 2019/7/22 19:00
     * 功能描述：拒绝申请
     */
    @ApiOperation(value = "拒绝添加好友", notes = "拒绝添加好友")
    @ApiImplicitParams({})
    @GetMapping("/refuseApply")
    public Result refuseApply(Long userId , Long friendId )
    {
        //插入数据库是以对方为User角度插入，所以拒绝时入参应以对方id为userId,我方id为friendId;
        friendService.refuseApply(userId ,friendId);
        return new Result().ok("成功拒绝");
    }

}
